<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php
	$latestNews = $this->db->select("blog.*")->from("blog")
						->join("blog_categories","blog.category_id=blog_categories.id")
						->where( array("blog_categories.slug" => 'latest-news' , "blog.status" => 'live') )
						->order_by('blog.created_on','desc')
						->limit(3)
						->get()->result();
		$html = "<ul>";
		foreach($latestNews as $item){
			$html .= "<li><div class=\"wrap\"><a href='".site_url("blog/view/".$item->slug)."' >".($item->title)."</a>".
					"<div class=\"news-content\">".($item->intro)."</div>
					<div class=\"readmore\"><a href='".site_url("blog/view/".$item->slug)."' >Read More</a>"."</div>
					</div></li>";
		}
		$html .= "</ul>";
	
	$livingMatch = $this->db->where(array("status"=>"living"))->limit(2)->get(TBL_MATCH)->result(); //,"show_feature"=>1
	$closedMatch = $this->db->where(array("status"=>"closed","show_feature"=>1))->get(TBL_MATCH)->result(); 
?>

<div id="scoreboard_div">	
	<div class="board">
		<div class="title"><h3>LIVE SCORE BOARD</h3></div>
		<div class="clrboth"></div>
		<?php foreach($livingMatch as $item):?>
			<?php 
				$MATCH = $this->match_entity->init('id', $item->id);
				$TEAM_HOME = clone_($this->team_entity->init('id', $MATCH->getHome()));
				$TEAM_AWAY = clone_($this->team_entity->init('id', $MATCH->getAway()));
			?>
			<div class="item">
				<div class="grid1"><span class="live"></span></div>
				<div class="grid4" style="text-align:center;"><h4><?php echo $MATCH->getTitle();?></h4></div>
				<div class="grid1" style="width:30px;">
					<span class="predict-text" title="Predict Now?">
						<a href="javascript:void(0);" onclick="go_predict(<?php echo $MATCH->getTournamentId();?>,<?php echo $MATCH->getId();?>,'<?php echo mCrypt($MATCH->getTournamentId().$MATCH->getId());?>');">P</a>
					</span>
				</div>
				<div class="clrboth"></div>
				
				<div class="grid2">
					<div class="team">
						<?php echo thumb($TEAM_HOME->getMyFlagTeam(),IMG_TEAMPIC_W,IMG_TEAMPIC_H);?>
						<div class="clrboth"></div>
						<span class="bold">
							<?php echo $MATCH->displayMatchInfo('home');?>
						</span>
						<div class="clrboth"></div>
					</div>
				</div>
			 
				<div class="grid1" style="text-align:center;width:80px;"><?php echo vs_image(); ?></div>
				
				<div class="grid2">
					<div class="team">
						<?php echo thumb($TEAM_AWAY->getMyFlagTeam(),IMG_TEAMPIC_W,IMG_TEAMPIC_H);?>
						<div class="clrboth"></div>
						<span class="bold">
							<?php echo $MATCH->displayMatchInfo('away');?>
						</span>
						<div class="clrboth"></div>
					</div>
				</div>
				
				<div class="clrboth"></div>
				
				<div class="result-text" style="text-align:center;">
					<?php echo $MATCH->displayMatchInfo('closed');?>
					<!--
					<div class="wrap-element">
						<a href='javascript:void(0);' onclick="return view_full_scorecard(<?php //echo $MATCH->getId();?>);" >View Scorecard</a>
					</div>	
					-->
				</div>
				
			</div>
		<?php endforeach; ?>
	</div>
	
	<div class="board" style="margin-left:5px;">
		<div class="title"><h3>RESULT</h3></div>
		<div class="clrboth"></div>
		<?php foreach($closedMatch as $item):?>
		 	<?php 
				$MATCH = $this->match_entity->init('id', $item->id);
				$TEAM_HOME = clone_($this->team_entity->init('id', $MATCH->getHome()));
				$TEAM_AWAY = clone_($this->team_entity->init('id', $MATCH->getAway()));
			?>
			<div class="item">
				<div class="grid1">&nbsp;</div>
				<div class="grid4" style="text-align:center;"><h4><?php echo $MATCH->getTitle();?></h4></div>
				<div class="clrboth"></div>
				
				<div class="grid2">
					<div class="team">
						<?php echo thumb($TEAM_HOME->getMyFlagTeam(),IMG_TEAMPIC_W,IMG_TEAMPIC_H);?>
						<div class="clrboth"></div>
						<span class="bold">
							<?php echo $MATCH->displayMatchInfo('home');?>
						</span>
						<div class="clrboth"></div>
					</div>
				</div>
			 
				<div class="grid1" style="text-align:center;width:80px;"><?php echo vs_image(); ?></div>
				
				<div class="grid2">
					<div class="team">
						<?php echo thumb($TEAM_AWAY->getMyFlagTeam(),IMG_TEAMPIC_W,IMG_TEAMPIC_H);?>
						<div class="clrboth"></div>
						<span class="bold">
							<?php echo $MATCH->displayMatchInfo('away');?>
						</span>
						<div class="clrboth"></div>
					</div>
				</div>
				
				<div class="clrboth"></div>
				
				<div class="result-text" style="text-align:center;">
					<?php echo $MATCH->displayMatchInfo('closed');?>
					<!--
					<div class="wrap-element">
						<a href='javascript:void(0);' onclick="return view_full_scorecard(<?php //echo $MATCH->getId();?>);" >View Scorecard</a>
					</div>		
					-->
				</div>
				
			</div>
		<?php endforeach; ?>	
	</div>
	
	<div class="board" style="margin-left:5px;width:319px;">
		<div class="title"><h3>CRICKET NEWS</h3></div>
		<div class="clrboth"></div>
		<div class="item" id="cricket-news">
			<?php echo $html; ?>
		</div>
	</div>
</div>